package com.example.dbsample.web;

import com.example.dbsample.model.entity.SysParamsEntity;
import com.example.dbsample.service.business.SysParamsService;
import com.example.dbsample.web.BaseRest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
* 参数管理;(sys_params)表控制层
* @author : http://www.chiner.pro
* @date : 2024-3-7
*/
@Api(tags = "参数管理对象功能接口")
@RestController
@RequestMapping("/sysParams")
public class SysParamsController extends BaseRest {
   @Autowired
   private SysParamsService sysParamsService;

   /**
    * 通过ID查询单条数据
    *
    * @param id 主键
    * @return 实例对象
    */
   @ApiOperation("通过ID查询单条数据")
   @GetMapping("/queryById/{id}")
   public ResponseEntity<SysParamsEntity> queryById(@PathVariable Long id){
       return ResponseEntity.ok(sysParamsService.querySysParamsById(id));
   }

   /**
    * 分页查询
    *
    * @param sysParams 筛选条件
    * @param pageRequest 分页对象
    * @return 查询结果
    */
   @ApiOperation("分页查询")
   @GetMapping("{paginQuery}")
   public ResponseEntity<Page<SysParamsEntity>> paginQuery(@RequestBody SysParamsEntity sysParams, PageRequest pageRequest){
       return ResponseEntity.ok(sysParamsService.paginQuery(sysParams, pageRequest));
   }

    @ApiOperation("获取唯一的元素")
    @GetMapping("/getOneSysParams/{id}")
    public ResponseEntity<Integer> getOneSysParams(@PathVariable Long id){
        return ResponseEntity.ok(sysParamsService.getOneSysParams(id));
    }


   /**
    * 新增数据
    *
    * @param sysParams 实例对象
    * @return 实例对象
    */
   @ApiOperation("新增数据")
   @PostMapping
   public ResponseEntity<SysParamsEntity> add(SysParamsEntity sysParams){
       return ResponseEntity.ok(sysParamsService.insertSysParams(sysParams));
   }

   /**
    * 更新数据
    *
    * @param sysParams 实例对象
    * @return 实例对象
    */
   @ApiOperation("更新数据")
   @PutMapping
   public ResponseEntity<SysParamsEntity> edit(SysParamsEntity sysParams){
       return ResponseEntity.ok(sysParamsService.updateSysParams(sysParams));
   }

   /**
    * 通过主键删除数据
    *
    * @param id 主键
    * @return 是否成功
    */
   @ApiOperation("通过主键删除数据")
   @DeleteMapping("/deleteById/{id}")
   public ResponseEntity<Boolean> deleteById(@PathVariable Long id){
       return ResponseEntity.ok(sysParamsService.deleteSysParamsById(id));
   }
}